package com.example.springbootexam.web;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.example.springbootexam.bean.Question;
import com.example.springbootexam.mapper.QuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ly
 * @since 2024-08-14
 */
@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    QuestionMapper questionMapper;

    @RequestMapping("query")
    public Page<Question> query(Question question,
                                @RequestParam(defaultValue = "1") int page,
                                @RequestParam(defaultValue = "10")int size){
        LambdaQueryWrapper<Question> lqw = new LambdaQueryWrapper<>();
        if(question.getType()!=null && question.getType().isBlank()==false){
            lqw.eq(Question::getType, question.getType());
        }
        if(question.getCourse()!=null && question.getCourse().isBlank()==false){
            lqw.eq(Question::getCourse, question.getCourse());
        }
        Page<Question> p = new PageDTO<>(page, size);
        return questionMapper.selectPage(p, lqw);
    }

}

